<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script th:src="@{/main/layuimini/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
    <script th:src="@{/main/js/jquery-2.1.3.min.js}" charset="utf-8"></script>
    <link rel="stylesheet" th:href="@{/main/layuimini/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/main/layuimini/css/public.css}" media="all">
    <script th:src=" @{/main/js/axios.min.js}"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="scoreRuleForm">
    <input type="hidden" name="id" th:value="${movie.id}">
    <div class="layui-form-item">
        <label class="layui-form-label required">电影名称</label>
        <div class="layui-input-block">
            <input type="text" id="hname" name="mName" th:value="${movie.mName}" lay-verify="required" lay-reqtext="电影名不能为空"
                   placeholder="请输入电影名称" value=""
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">电影类型</label>
        <div class="layui-input-block">
            <input type="text" id="hrow" name="mType" th:value="${movie.mType}" lay-verify="required" lay-reqtext="电影类型不能为空"
                   placeholder="请输入电影类型"
                   value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">电影时长</label>
        <div class="layui-input-block">
            <input type="text" id="hcol" name="mLength" th:value="${movie.mLength}" lay-verify="required|number" lay-reqtext="电影时长不能为空"
                   placeholder="请输入电影时长"
                   value="" class="layui-input">
            <!--            <tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">导演</label>
        <div class="layui-input-block">
            <input type="text" id="mDirector" name="mDirector" th:value="${movie.mDirector}" lay-verify="required" lay-reqtext="导演不能为空"
                   placeholder="请输入导演"
                   value="" class="layui-input">
            <!--            <tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">演员</label>
        <div class="layui-input-block">
            <input type="text" id="mActor" name="mActor" th:value="${movie.mActor}" lay-verify="required" lay-reqtext="演员不能为空"
                   placeholder="请输入演员"
                   value="" class="layui-input">
            <!--            <tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" th:field="${movie.status}" value="上映中" title="上映中">
            <input type="radio" name="status" th:field="${movie.status}" value="未上映" title="未上映">
            <input type="radio" name="status" th:field="${movie.status}" value="已下线" title="已下线">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">上映时间</label>
        <div class="layui-input-block">
            <input id="mDate" name="mDate" th:value="${movie.mDate}" lay-verify="required" lay-reqtext="上映时间不能为空"
                   value="" class="layui-input mDate">
            <!--            <tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">简介</label>
        <div class="layui-input-block">
            <textarea id="hdesc" name="mIntroduction" th:text="${movie.mIntroduction}" class="layui-textarea" placeholder="请输入简介"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" id="submit" lay-submit lay-filter="saveBtn">立即提交</button>
        </div>
    </div>
</div>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '.mDate' //指定元素
        });
    });
    // 获取url参数值
    function getQueryVariable(key) {
        var url = location.search;
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        var value = (theRequest[key] == null || theRequest[key] == undefined) ? null : theRequest[key];
        return value;
    }
    function hint(data) {
        layer.msg(data, {
            icon: 1,
            time: 1000,
            end: function () {
                parent.refresh();//刷新到表格
                // 关闭弹出层
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);
            }
        });
        return false;
    }
    function hintError(data) {
        layer.msg(data, {
            icon: 5,
            time: 1000,
            end: function () {
                $("#submit").removeAttr("disabled", "disabled").removeClass("layui-btn-disabled");
            }
        });
        return false;
    }

    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        form.verify({
            money:[
                /^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,2})?$/,
                '请输入正确的金额'
            ],
            mName:[
                /^[\u4e00-\u9fa5]{2,18}[0-9]?$/,
                '请输入正确的电影名'
            ]
        })
        var id = getQueryVariable("id");
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $("#submit").attr("disabled", "disabled").addClass("layui-btn-disabled");
            axios.post(
                "/movie/updateMovie",
                data.field
            ).then(function (response){
                var data = response.data;
                if (data=="修改成功")
                hint(data)
                else
                    hintError(data);
            })
        });
    });
</script>
</body>
</html>